package com.km.component;

import com.km.app.domain.R;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class SpringExceptionHandler {

    private final static Log log = LogFactory
            .getLog(SpringExceptionHandler.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public R defaultErrorHandler(HttpServletRequest req, Exception ex) throws Exception {
        log.error(SpringExceptionHandler.class.getName(), ex);
        return new R().fail().setData(ex.toString()).setMessage("系统异常");
    }
}
